cimport numpy as cnp
cimport cython

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.initializedcheck(False)
def preprocess_cpy(
        cnp.ndarray[cnp.uint8_t, ndim=3] src,
        cnp.ndarray[cnp.float32_t, ndim=3] dst,
        int height,
        int width,
        ) -> None:
    cdef:
        int h, w
        int hw = height * width
        float inv_255 = 1. / 255.
        cnp.uint8_t* src_ptr = &src[0, 0, 0]
        cnp.float32_t* dst_ptr = &dst[0, 0, 0]
        size_t src_offset, dst_r, dst_g, dst_b
        float src_b, src_g, src_r

    for h in range(height):
        for w in range(width):
            src_offset = h * width * 3 + w * 3
            dst_r = h * width + w
            dst_g = hw + dst_r
            dst_b = hw + hw + dst_r

            src_r = src_ptr[src_offset + 2]
            src_g = src_ptr[src_offset + 1]
            src_b = src_ptr[src_offset]

            dst_ptr[dst_r] = src_r * inv_255
            dst_ptr[dst_g] = src_g * inv_255
            dst_ptr[dst_b] = src_b * inv_255